package gui;

import dataconnect.Investment;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import java.awt.BorderLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * description: AddItem
 * 添加单个项目页面
 * 
 * @author what-is-me
 * @date 2022/1/3 22:55
 */
public class AddItem extends JPanel {
    JTextField[] text = new JTextField[6];

    public AddItem() {
        /**
         * Description: AddItem
         * 
         * @param :
         * @return {@link null}
         * @throws
         * @author what-is-me
         * @date 2022/1/3 23:25
         */
        super(null);
        JPanel jp = new JPanel(new BorderLayout());
        GridBagPanel p = new GridBagPanel();
        jp.add(p, BorderLayout.CENTER);
        for (int i = 0; i < 6; i++) {
            JLabel t = new JLabel(Investment.tag[i]);
            t.setFont(new Font("宋体", Font.PLAIN, 16));
            p.add(t, 0, i, 1, 1, 0, 5);
            text[i] = new JTextField(30);
            p.add(text[i], 1, i, 2, 1, 0, 5);
        }
        JButton b = new JButton("提交");
        b.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                Message.msg = "submit";
                Message.args = get();
            }
        });
        GridBagPanel tmp = new GridBagPanel();
        tmp.add(b, 0, 0, 1, 1, 0, 5);
        jp.add(tmp, BorderLayout.SOUTH);
        jp.setSize(720, 480);
        add(jp);
        jp.setLocation((1080 - 720) / 2, (720 - 480) / 2);
    }

    String[] get() {
        /**
         * Description: get
         * 获取所有输入
         * 
         * @param :
         * @return {@link String[]}
         * @throws
         * @author what-is-me
         * @date 2022/1/3 23:25
         */
        String[] ret = new String[6];
        for (int i = 0; i < 6; i++) {
            ret[i] = text[i].getText();
        }
        return ret;
    }
}